package _2022.hot100._12_整数转罗马数字;

/**
 * @author： YHSimon
 * @date： 2022-08-11 23:51
 */
public class Solution {
    public String intToRoman(int num) {
        int[] values=new int[]{1000,900,500,400,100,90,50,40,10,9,5,4,1};
        String[] symbols={"M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"};
        StringBuilder sb = new StringBuilder();
        for(int i=0;i<values.length;i++){
            int value=values[i];
            String symbol=symbols[i];
            while(num>=value){
                num-=value;
                sb.append(symbol);
            }
            if (num==0){
                break;
            }
        }
        return sb.toString();
    }
}
